package com.springboot2.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.springboot2.domain.Book;
import com.springboot2.service.IBookService;
import io.swagger.annotations.Api;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//表现层
//因为 books 名称一样 必须 注释掉 或者 改名
@Api(tags = "mybatis编写 先别用")
@RestController
@RequestMapping("/booksO")
public class BookController {


    @Autowired
    private IBookService bookService;
    @GetMapping
    public List<Book> getAll(){

        return  bookService.list();
    }
    @PostMapping
    public Boolean save(@RequestBody Book book){
        return bookService.save(book);
    }

//    update @RequestBody 为传递json
    @PutMapping
    public Boolean update(@RequestBody Book book){
        return bookService.updateById(book);
    }
    @DeleteMapping("{id}")
    public Boolean delete(@PathVariable Integer id){
        return bookService.deleteCxyBook(id);
    }
//    删除和 查询单个 一个用路径来
    @GetMapping("{id}")
    public  Book getById(@PathVariable Integer id){
        return bookService.getById(id);
    }
//    分页
    @GetMapping("{currentPage}/{pageSize}")
    public IPage<Book> getPage(@PathVariable int currentPage,@PathVariable int pageSize){
        return bookService.getPage(currentPage,pageSize, null);
    }

}
